<?php
namespace Home\Controller;

use Think\Controller;


class EcxcelController extends Controller
{
    public function index()
    {
        $this->display('index');
    }

    public function getExcel()
    {
        if (!empty($_FILES)) {
            $upload = new \Think\Upload();// 实例化上传类
            $filepath = './Uploads/Excle/';
            if(!is_dir($filepath)){
                mkdir($filepath, '7777', true);
            }
            $upload->exts = array('xlsx', 'xls');// 设置附件上传类型
            $upload->rootPath = $filepath; // 设置附件上传根目录
            $upload->saveName = 'time';
            $upload->autoSub = false;
            $info = $upload->upload();

            if (!$info) {
                $this->error($upload->getError());
            }else{
                $excelfile = ($filepath.$info['import']['savename']);
            }
            //提交到excel 转换器
            $excel = new \Org\PHPExcel\Excel;
            $ret = $excel->getExcel($excelfile);
            echo $ret;
        }

    }
}